package com.morpheus.redis.redisson.cluster;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

public class OnEnableRedissonClusterCondition extends SpringBootCondition {
	private static final Logger LOGGER = LoggerFactory.getLogger(OnEnableRedissonClusterCondition.class);

	@Override
	public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
		Environment environment = context.getEnvironment();
		boolean isCluster = environment.containsProperty("spring.redis.cluster.nodes");
		boolean isRedisson = environment.containsProperty("spring.redis.redisson.config");
		ConditionOutcome conditionOutcome = new ConditionOutcome(isCluster && isRedisson,
				"Enable Redis-Cluster client Redisson.");
		return conditionOutcome;
	}
}
